<template>
  <view class="form-record-card" :style="{ padding: padding }">
    <view class="card-left">
      <view class="card-title">
        <text class="title">{{ title }}</text>
        <CustomTag
          v-if="sta === ServiceFormStatusEnum.Down"
          text="未开放"
          backgroundColor="#FFF4E7"
          color="#EA5E0E"
        ></CustomTag>
      </view>
      <view class="card-info">
        <view class="avatar-name">
          <TImage
            :src="avatarImage"
            width="40rpx"
            height="40rpx"
            errorImgType="person"
            borderRadius="40rpx"
          ></TImage>
          <text class="name">{{ name }}</text>
        </view>
        <text class="date-time">{{ dateTimeStr }} 发布</text>
      </view>
    </view>

    <slot name="right">
      <view class="card-right" @click="emtis('click-right')">
        <text class="num">{{ numText }}</text>
        <text class="num-unit">填写数量</text>
      </view>
    </slot>
  </view>
  <view class="disFlxAC flexEnd py-12 px-16 button-area">
    <TButton
      text="表单管理"
      type="none"
      :customStyle="{
        display: 'inline-block',
        backgroundColor: '#F2F3F5',
        color: '#333333',
        marginLeft: '24rpx',
      }"
      custom-class="h-24 linh-24 br-12"
      @click="handleClick"
    />
    <TButton
      text="分享表单"
      type="none"
      :customStyle="{
        display: 'inline-block',
        backgroundColor: '#F2F3F5',
        color: '#333333',
        marginLeft: '24rpx',
      }"
      custom-class="h-24 linh-24 br-12"
      @click="emtis('onShare')"
    />
  </view>
</template>
<script setup lang="ts">
  import { propTypes } from '@/utils/propTypes';
  import { computed } from 'vue';
  import CustomTag from '../CustomTag/index.vue';
  import TImage from '@/components/TImage/index.vue';
  import { ServiceFormStatusEnum } from '@/enums/serviceFormEnum';
  import TButton from '@/components/TButtonGroup/TButton.vue';

  const props = defineProps({
    title: propTypes.string.def(''),
    avatarImage: propTypes.string.def(''),
    name: propTypes.string.def(''),
    dateTimeStr: propTypes.string.def(''),
    padding: propTypes.string.def('24rpx'),
    num: propTypes.number.def(0),
    sta: propTypes.number.def(ServiceFormStatusEnum.Up),
  });

  const emtis = defineEmits(['click', 'click-right', 'onShare']);

  const numText = computed(() => {
    return props.num > 99999 ? '99999+' : props.num;
  });

  const handleClick = () => {
    emtis('click');
  };
</script>
<style lang="scss" scoped>
  .form-record-card {
    background-color: white;
    display: flex;
    justify-content: space-between;
    border-top-left-radius: 16rpx;
    border-top-right-radius: 16rpx;
    .card-left {
      display: flex;
      flex-direction: column;
      gap: 16rpx;
      flex: 1;
      .card-title {
        display: flex;
        gap: 16rpx;
        align-items: flex-start;
        padding-right: 16rpx;
        .title {
          word-break: break-all;
          font-size: 32rpx;
          line-height: 48rpx;
        }
      }
      .card-info {
        display: flex;
        gap: 16rpx;
        align-items: center;
        .avatar-name {
          display: flex;
          align-items: center;
          gap: 8rpx;
          .name {
            font-size: 24rpx;
            line-height: 32rpx;
            color: #666664;
          }
        }
        .date-time {
          color: #999996;
          font-size: 24rpx;
          line-height: 32rpx;
        }
      }
    }
    .card-right {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 16rpx;
      box-shadow: 1px 0px 0px 0px #ebedf0 inset;
      padding-left: 24rpx;
      .num {
        color: #2878ff;
        font-size: 32rpx;
        line-height: 48rpx;
      }
      .num-unit {
        font-size: 24rpx;
        line-height: 36rpx;
        color: #999996;
      }
    }
  }

  .button-area {
    border-bottom-left-radius: 16rpx;
    border-bottom-right-radius: 16rpx;
    border-top: 1px solid #ebedf0;
    background-color: #fff;
  }
</style>
